{
  LX Handles module

  Based on modo's SDK lxhandles.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.   Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012 David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit Lx_Handles;

{$mode objfpc}{$H+}

interface

uses
  Lx_Result, Lx_VMath;

const
  LXf_EVTRAN_SNAPS           = 0;
  LXf_EVTRAN_NOSNAP          = 1;
  LXf_EVTRAN_NOQUANT         = 2;
  LXf_EVTRAN_NOCONST         = 4;

  LXf_EVTRAN_UNSNAPPED       = LXf_EVTRAN_NOSNAP  or
                               LXf_EVTRAN_NOQUANT or
                               LXf_EVTRAN_NOCONST   ;

  LXf_GUIDE_LINE             = 1;
  LXf_GUIDE_PLANE            = 2;

  LXf_GUIDE_POINT            = LXf_GUIDE_PLANE or
                               LXf_GUIDE_LINE    ;

  LXf_GUIDE_SNAP             = LXf_GUIDE_POINT;

  LXf_GUIDE_SNAP_NONE        = 0;
  LXf_GUIDE_SNAP_AXIS_X      = 1;  //  1 shl 0
  LXf_GUIDE_SNAP_AXIS_Y      = 2;  //  1 shl 1
  LXf_GUIDE_SNAP_AXIS_Z      = 4;  //  1 shl 2
  LXf_GUIDE_SNAP_ALLAXES     = 7;   {  LXf_GUIDE_AXIS_X  or
                                       LXf_GUIDE_AXIS_Y  or
                                       LXf_GUIDE_AXIS_Z     }

  LXf_GEOCONS_POINT          = $01;
  LXf_GEOCONS_VECTOR         = $02;

  LXi_VDRAWf_MASK            = $FF shl 24;
  LXi_VDRAWf_FILL            = 1   shl 31;
  LXi_VDRAWf_DASH            = 1   shl 30;
  LXi_VDRAWf_CUSTOM0         = 1   shl 24;
  LXi_VDRAWf_CUSTOM1         = 1   shl 25;
  LXi_VDRAWf_CUSTOM2         = 1   shl 26;
  LXi_VDRAWf_CUSTOM3         = 1   shl 23;

  LXi_VDRAWf_AXARROW         = LXi_VDRAWf_CUSTOM0;

  LXi_THANDf_SMALL           = 1 shl 16;
  LXi_THANDf_HOT             = 1 shl 17;
  LXi_THANDf_HIT             = 1 shl 18;
  LXi_THANDf_CONST           = 1 shl 19;
  LXi_THANDf_GHOST           = 1 shl 20;
  LXi_THANDf_FLIP            = 1 shl 21;

  LXi_THANDf_AXES            = 3 shl 24;
  LXi_THANDf_AXIS_X          = 1 shl 24;
  LXi_THANDf_AXIS_Y          = 2 shl 24;
  LXi_THANDf_AXIS_Z          = 3 shl 24;

  LXi_THANDv_MASK            = $FFFF;

  LXi_EVTRAN_CONSTRAIN_NONE  = 0  ;
  LXi_EVTRAN_CONSTRAIN_LINE  = 1  ;
  LXi_EVTRAN_CONSTRAIN_PLANE = 2  ;

  LXi_GUIDE_OFF              = 0  ;
  LXi_GUIDE_SUGGEST          = 1  ;
  LXi_GUIDE_CHOSEN           = 2  ;
  LXi_GUIDE_FLAGS_NONE       = $00;
  LXi_GUIDE_FLAGS_ALWAYS     = $01;

  LXu_EVENTTRANSLATEPACKET   = '{81B7CACE-DB90-4AD7-AE93-42C23E62130D}';
  LXu_EVENTGUIDE             = '{B2A11425-25DE-4628-839C-995020BD8DF1}';
  LXu_GEOCONSTRAINTPACKET    = '{0589BA62-5A11-453d-B84A-1C7CF30A0D35}';
  LXu_HANDLEDRAW             = '{EEC6665A-BB44-48A4-8F8C-B4BCDF2ED880}';
  LXu_SHAPEDRAW              = '{DC46A7E2-2849-46CE-9075-2394E04EB3AE}';

  LXsP_TOOL_EVENTTRANS       = 'toolEventTranslate';

type
  ILxShapeDraw = interface
  [LXu_SHAPEDRAW]
    procedure Circle        (const Col    : LXtVector;
                                   Alpha  : Double   ;
                             const Pos    : LXtVector;
                                   Rad    : Double   ;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure Ellipse       (const Col    : LXtVector;
                                   Alpha  : Double   ;
                             const Pos    : LXtVector;
                             const Rad    : LXtVector;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure Pill          (const Col    : LXtVector;
                                   Alpha  : Double   ;
                             const Pos    : LXtVector;
                                   Width  ,
                                   Height ,
                                   Rad    : Double   ;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure Bone          (const Col    : LXtVector;
                                   RLen   : Double   ;
                                   Active : Integer  ) ;
    procedure Arc           (const Col    : LXtVector;
                                   Alpha  : Double   ;
                             const Pos    : LXtVector;
                                   Rad    ,
                                   Start  ,
                                   &End   : Double   ;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure Plane         (const Col    : LXtVector;
                             const Pos    : LXtVector;
                             const Size   : LXtVector;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure Ellipsoid     (const Col    : LXtVector;
                                   Alpha  : Double   ;
                             const Pos    : LXtVector;
                             const Rad    : LXtVector;
                                   Flags  : Integer  ) ;
    procedure Cube          (const Col    : LXtVector;
                             const Pos    : LXtVector;
                             const Size   : LXtVector;
                                   Flags  : Integer  ) ;
    procedure CubeFill      (const Col    : LXtVector;
                                   Alpha  : Double   ;
                             const Pos    : LXtVector;
                             const Size   : LXtVector;
                                   Flags  : Integer  ) ;
    procedure BoxShape      (const ColW   : LXtVector;
                             const ColF   : LXtVector;
                             const Pos    : LXtVector;
                             const Size   : LXtVector;
                                   Flags  : Integer  ) ;
    procedure Pyramid       (const Col    : LXtVector;
                             const Pos    : LXtVector;
                             const Size   : LXtVector;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure PyramidShape  (const ColW   : LXtVector;
                             const ColF   : LXtVector;
                             const Pos    : LXtVector;
                             const Size   : LXtVector;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure Rhombus       (const Col    : LXtVector;
                             const Pos    : LXtVector;
                             const Size   : LXtVector;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure RhombusShape  (const ColW   : LXtVector;
                             const ColF   : LXtVector;
                             const Pos    : LXtVector;
                             const Size   : LXtVector;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure Cone          (const Col    : LXtVector;
                             const Pos    : LXtVector;
                                   Rad    ,
                                   Height : Double   ;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure ConeShape     (const ColW   : LXtVector;
                             const ColF   : LXtVector;
                             const Pos    : LXtVector;
                                   Radius ,
                                   Height : Double   ;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure Cylinder      (const Col    : LXtVector;
                             const Pos    : LXtVector;
                                   Rad    ,
                                   Height : Double   ;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure CylinderShape (const ColW   : LXtVector;
                             const ColF   : LXtVector;
                             const Pos    : LXtVector;
                                   Radius ,
                                   Height : Double   ;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure SphereShape   (const ColW   : LXtVector;
                             const ColF   : LXtVector;
                             const Pos    : LXtVector;
                                   Radius : Double   ;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure CircleShape   (const ColW   : LXtVector;
                             const ColF   : LXtVector;
                             const Pos    : LXtVector;
                                   Radius : Double   ;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure PlaneShape    (const ColW   : LXtVector;
                             const ColF   : LXtVector;
                             const Pos    : LXtVector;
                             const Size   : LXtVector;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure RadialMap     (      Image  : IUnknown ;
                             const Col    : LXtVector;
                             const Cen    : LXtVector;
                                   Size   : Double   ;
                                   Sel    ,
                                   Flags  : Integer  ) ;
    procedure RadialRays    (      Image  : IUnknown ;
                             const Col    : LXtVector;
                             const Cen    : LXtVector;
                                   Size   : Double   ;
                                   Sel    ,
                                   Flags  : Integer  ) ;
    procedure Link          (const Col    : LXtVector;
                             const PosS   : LXtVector;
                             const PosE   : LXtVector;
                                   Solid  ,
                                   Flags  : Integer  ) ;
    procedure BBox          (const Col    : LXtVector;
                                   Size   : Double   ;
                                   Flags  : Integer  ) ;
    procedure Arrow         (const Col    : LXtVector;
                             const Pos    : LXtVector;
                                   Size   : Double   ;
                                   Axis   ,
                                   Flags  : Integer  ) ;
    procedure Axis          (const Col    : LXtVector;
                             const Pos    : LXtVector;
                             const Size   : LXtVector;
                                   Flags  : Integer  ) ;
    procedure Star          (const Col    : LXtVector;
                             const Pos    : LXtVector;
                             const Rad    : LXtVector;
                                   Flags  : Integer  ) ;
    procedure Cross         (const Col    : LXtVector;
                             const Pos    : LXtVector;
                             const Rad    : LXtVector;
                                   Flags  : Integer  ) ;
    procedure Line          (const V0     : LXtVector;
                             const V1     : LXtVector;
                             const Col    : LXtVector;
                                   Alpha  : Double   ;
                                   Flags  : Integer  ) ;
    procedure CSeg          (const Cen    : LXtVector;
                             const Offset : LXtVector;
                                   Screen : Double   ;
                             const Col    : LXtVector;
                                   Flags  : Integer  ) ;
    procedure PlaneIndicator(const Col    : LXtVector;
                                   Alpha  : Double   ;
                             const Pos    : LXtVector;
                                   Rad    : Double   ;
                                   Axis_  ,
                                   Flags  : Integer  ) ;
    procedure CrossHair     (const Col    : LXtVector;
                                   Alpha  : Double   ;
                             const Pos    : LXtVector;
                                   Flags  : Integer  ) ;
    procedure PreciseHandle (const Col    : LXtVector;
                                   Alpha  : Double   ;
                             const Pos    : LXtVector;
                             const Size   : LXtVector;
                                   Flags  : Integer  ) ;
  end;

  ILxHandleDraw = interface
  [LXu_HANDLEDRAW]
    procedure Handle           (const Pos    : LXtVector;
                                const Mat    : LXtMatrix;
                                      Part   ,
                                      Flags  : Integer  ) ;
    procedure AxisHandle       (const Pos    : LXtVector;
                                const Mat    : LXtMatrix;
                                      Axis   ,
                                      Part   : Integer  ;
                                      Len    : Double   ;
                                      Flags  : Integer  ) ;
    procedure MoveHandle       (const Pos    : LXtVector;
                                const Mat    : LXtMatrix;
                                      Axis   ,
                                      Part   ,
                                      Flags  : Integer  ) ;
    procedure RotateHandle     (const Pos    : LXtVector;
                                const Mat    : LXtMatrix;
                                      Axis   ,
                                      Part   : Integer  ;
                                      SAngle ,
                                      EAngle : Double   ;
                                      Facing ,
                                      Flags  : Integer  ) ;
    procedure RotateMouseHandle(const Center : LXtVector;
                                const Pos    : LXtVector;
                                const Mat    : LXtMatrix;
                                      Axis   ,
                                      Part   ,
                                      Flags  : Integer  ) ;
    procedure ScaleHandle      (const Pos    : LXtVector;
                                const Mat    : LXtMatrix;
                                      Axis   ,
                                      Part   : Integer  ;
                                      Offset : Double   ;
                                      Line   ,
                                      Flags  : Integer  ) ;
    procedure CrossHandle      (const Pos    : LXtVector;
                                const Mat    : LXtMatrix;
                                      Part   ,
                                      Flags  : Integer  ) ;
    procedure PointHandle      (const Pos    : LXtVector;
                                      Part   ,
                                      Flags  : Integer  ) ;
    procedure XHandle          (const Pos    : LXtVector;
                                const Mat    : LXtMatrix;
                                      Part   ,
                                      Flags  : Integer  ) ;
    procedure PlaneHandle      (const Pos    : LXtVector;
                                const Mat    : LXtMatrix;
                                      Axis   ,
                                      Part   ,
                                      Flags  : Integer  ) ;
  end;

  ILxEventTranslatePacket = interface
  [LXu_EVENTTRANSLATEPACKET]
    function  ToModel            (ToolVector : IUnknown ;
                                  Pos        : LXtVector;
                                  Axis       : LXtVector) : Integer;
    procedure ToModelLine        (ToolVector : IUnknown ;
                                  Center     : LXtVector;
                                  Dir        : LXtVector;
                                  Pos        : LXtVector) ;
    procedure ToModelPlane       (ToolVector : IUnknown ;
                                  Center     : LXtVector;
                                  Normal     : LXtVector;
                                  Pos        : LXtVector) ;
    procedure ModelDelta         (ToolVector : IUnknown ;
                                  Handle     : LXtVector;
                                  Delta      : LXtVector) ;
    procedure ModelLineDelta     (ToolVector : IUnknown ;
                                  Center     : LXtVector;
                                  Dir        : LXtVector;
                                  Handle     : LXtVector;
                                  Delta      : LXtVector) ;
    procedure ModelPlaneDelta    (ToolVector : IUnknown ;
                                  Center     : LXtVector;
                                  Normal     : LXtVector;
                                  Handle     : LXtVector;
                                  Delta      : LXtVector) ;
    procedure HitHandle          (ToolVector : IUnknown ;
                                  Handle     : LXtVector) ;
    procedure GetNewPosition     (ToolVector : IUnknown ;
                                  Pos        : LXtVector) ;
    procedure SetLinearConstraint(ToolVector : IUnknown ;
                                  Center     : LXtVector;
                                  Dir        : LXtVector) ;
    procedure SetPlanarConstraint(ToolVector : IUnknown ;
                                  Center     : LXtVector;
                                  Normal     : LXtVector) ;
    function  GetConstraint      (ToolVector : IUnknown ;
                                  Center     : LXtVector;
                                  Vector     : LXtVector) : Integer;
    procedure SetSnapRange       (Inner      : Double   ;
                                  Outer      : Double   ) ;
    procedure ScreenToRay        (ToolVector : IUnknown ;
                                  X          : Single   ;
                                  Y          : Single   ;
                                  Pos        : LXtVector;
                                  Dir        : LXtVector) ;
    procedure AddGuide           (Guide      : IUnknown ;
                                  Client     : Pointer  ) ;
    function  RemoveGuide        (Guide      : IUnknown ;
                                  Client     : Pointer  ) : Integer;
  end;

  ILxEventGuide = interface
  [LXu_EVENTGUIDE]
    function  Limits      (Inner      : Double   ;
                           Outer      : Double   ) : Integer;
    function  Proximity   (ToolVector : IUnknown ;
                           Pos        : LXtVector;
                           Dist       : PDouble  ;
                           Priority   : PInteger ;
                           Element    : Pointer  ) : Integer;
    function  SetDrawState(Flags      : Integer  ) : Integer;
    procedure SetFlags    (Flags      : Integer  ) ;
    function  Flags                                : Integer;
  end;

  ILxGeoConstraintPacket = interface
  [LXu_GEOCONSTRAINTPACKET]
    function  PointConstrain (Pos   : LXtVector;
                              Delta : LXtVector) : LxResult;
    function  VectorConstrain(Pos   : LXtVector;
                              Delta : LXtVector) : LxResult;
    function  Flags                              : Integer ;
    procedure ModeMaskSet    (Mask  : Integer  ) ;
  end;

function LXi_THANDv_AXIS(F : Integer) : Integer;

implementation

function LXi_THANDv_AXIS(F : Integer) : Integer; inline;
begin
  Result := (((F and LXi_THANDf_AXES) shr 24) - 1);
end;

end.

